<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/**
 * @filename mnews.php
 * 新闻公告模型
 * @author hmw
 *
 */

class mnews extends Model {

    function mnews() {
        parent::Model();
    }
	
    /**
     * 显示公告列表
     * @param $limit
     * @param $state
     * @return array
     */
    function get_news_list($limit=0,$state=1,$type=''){
    	$this->db->where('news_state',$state);
    	if ($type !== ''){
    		$this->db->where('news_type',$type);
    	}
    	$this->db->order_by('news_time','desc');
    	if($limit){
    		$this->db->limit($limit);
    	}
    	$query = $this->db->get('news');
    	$temp = $query->result_array();
    	$arr = array();
    	if($temp){
    		foreach($temp as $t){
    			if($t['color']){
    				$t['title_style'] = 'class="'.$t['color'].'_font';
    			}
    			if ($t['is_bold']){
    				$t['title_style'] .= ' bold_font';
    			}
    			$t['title_style'] .= '"';
    			$arr[] = $t;
    		}
    	}
    	return $arr;
    }
    
    /**
     * 添加新公告
     * @param $array
     * @return TRUE/FALSE
     */
    function insert_news($array){
    	return $this->db->insert('news',$array);
    }
    
    /**
     * 获取某个公告详细信息
     * @param $id
     * @return array
     */
    function get_news_detail($id){
    	$query = $this->db->get_where('news',array('id'=>$id));
    	$info = $query->row_array();
    	$info['news_date'] = date('Y-m-d',strtotime($info['news_time']));
    	return $info;
    }
    
    /**
     * 更新公告详情
     * @param $id
     * @param $array
     * @return TRUE/FALSE
     */
    function update_news($id,$array){
    	return $this->db->update('news',$array,array('id'=>$id));
    }
    
}

?>